module LinesOfCode

import General;
import IO;
import String;

public int CountTotalLinesOfCode(list[loc] files)
{	
	return (0 | it + LinesOfCode(f) | loc f <- files);
}

public int LinesOfCode(loc location)
{
	int count = 0;
	bool go = true;
	
	for(line <- readFileLines(location))
	{
		str trimmedLine = trim(line);
		
		if(trimmedLine != "")
		{
			if(trimmedLine !=  "{" && trimmedLine !=  "}")
			{
				if(startsWith(trimmedLine, "/*"))
					go = false;
				
				if(!startsWith(trimmedLine,"/") && !startsWith(trimmedLine,"*"))//Filter all kind of commets out. // or /* or *
	 				if(go)
						count += 1;
				
				if(endsWith(trimmedLine, "*/"))
					go = true;
			}
		}
	}
	
	return count;
}

public str LinesOfCodeScore(int totalLinesOfCode)
{	
	str operator = "";
	if(totalLinesOfCode <= 6600)
		operator = "++";
	else if(totalLinesOfCode <= 246000)
		operator = "+";
	else if(totalLinesOfCode <= 665000)
		operator = "o";
	else if(totalLinesOfCode <= 1310000)
		operator = "-";
	else
		operator = "--";
		
	return operator;
}